/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.thinkgem.jeesite.modules.accountinfo.service;

import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.thinkgem.jeesite.common.persistence.Page;
import com.thinkgem.jeesite.common.service.CrudService;
import com.thinkgem.jeesite.modules.accountinfo.dao.AccountInfoAddressDao;
import com.thinkgem.jeesite.modules.accountinfo.entity.AccountInfo;
import com.thinkgem.jeesite.modules.accountinfo.entity.AccountInfoAddress;

/**
 * 添加地址Service
 * @author ljh
 * @version 2016-12-15
 */
@Service
@Transactional(readOnly = true)
public class AccountInfoAddressService extends CrudService<AccountInfoAddressDao, AccountInfoAddress> {

	@Autowired
	AccountInfoAddressDao dao;
	public AccountInfoAddress get(String id) {
		return dao.get(id);
	}
	
	public List<AccountInfoAddress> findListByAccountId(AccountInfo accountInfo){
	    AccountInfoAddress entity = new AccountInfoAddress();
        entity.setAccountInfo(accountInfo);
	    return dao.findListByAccountId(entity);
	}
	
	public List<AccountInfoAddress> addressList(AccountInfo accountInfo){
	    AccountInfoAddress entity = new AccountInfoAddress();
	    entity.setAccountInfo(accountInfo);
        return dao.addressList(entity);
    }
	
	public List<AccountInfoAddress> findList(AccountInfoAddress accountInfoAddress) {
		return dao.findList(accountInfoAddress);
	}
	
	public Page<AccountInfoAddress> findPage(Page<AccountInfoAddress> page, AccountInfoAddress accountInfoAddress) {
		
	    accountInfoAddress.setPage(page);
	    List<AccountInfoAddress> list = dao.findList(accountInfoAddress);
        page.setList(dao.findList(accountInfoAddress));
	    return page;
	}
	
	@Transactional(readOnly = false)
	public void save(AccountInfoAddress accountInfoAddress) {
		if(StringUtils.isNoneBlank(accountInfoAddress.getId())){
				//accountInfoAddress.getId()!=null&&accountInfoAddress.getId()!=""){
			dao.update(accountInfoAddress);
		}else{
			accountInfoAddress.setId(null);
				//accountInfoAddress.getId()!=""||accountInfoAddress.getId()==null){
			dao.insert(accountInfoAddress);
		}
	}
	
	@Transactional(readOnly = false)
	public void delete(AccountInfoAddress accountInfoAddress) {
	    dao.delete(accountInfoAddress);
	}
	public AccountInfoAddress getAddressDefault(AccountInfo accountInfo) {
		AccountInfoAddress entity = new AccountInfoAddress();
	    entity.setAccountInfo(accountInfo);
		return dao.getAddressDefault(entity);
	}
	public List<AccountInfoAddress> getAddressCommon(AccountInfo accountInfo) {
		AccountInfoAddress entity = new AccountInfoAddress();
	    entity.setAccountInfo(accountInfo);
		return dao.getAddressCommon(entity);
	}
	
	@Transactional(readOnly = false)
	public AccountInfoAddress insertAccountInfoAddress(AccountInfoAddress accountInfoAddress) {
		accountInfoAddress.setId(null);
		dao.insertAccountInfoAddress(accountInfoAddress);
		return accountInfoAddress;
	}
}